package com.xsmart.order.services;

import com.baomidou.mybatisplus.plugins.Page;
import com.xsmart.common.constant.ResultConstant;
import com.xsmart.common.entity.RequestBean;
import com.xsmart.common.entity.ResponseBean;
import com.xsmart.order.dao.YyDetailUrlDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 周志成
 */
@Service
public class YyDetailUrlService {
    @Autowired
    YyDetailUrlDao yyDetailUrlDao;

    /**
     * 查询广告推荐转入地址
     * @param requestBean
     * @return
     */
    public ResponseBean queryYyDetailUrl(RequestBean requestBean){
        int currentPage = requestBean.getRequestParamInteger("currentPage",1);
        int pageSize = requestBean.getRequestParamInteger("pageSize",10);
        String remark = requestBean.getRequestParamString("remark");
        Integer status = requestBean.getRequestParamInteger("status");
        Map<String,Object> yyDetailUrlMap = new HashMap<>(2);
        yyDetailUrlMap.put("remark",remark);
        yyDetailUrlMap.put("status",status);
        ResponseBean responseBean = requestBean.getResponseBean();
        Page<Map<String,Object>> page = new Page<>(currentPage,pageSize);
        page.setRecords(yyDetailUrlDao.queryYyDetailUrl(page,yyDetailUrlMap));
        responseBean.addResultPageItem("adAddressList",page);
        responseBean.setResult(ResultConstant.SUCCESS);
        return responseBean;
    }

    /**
     * 新增广告推荐装入地址
     * @param requestBean
     * @return
     */
    public ResponseBean addYyDetailUrl(RequestBean requestBean){
        ResponseBean responseBean = requestBean.getResponseBean();
        String detailUrl = requestBean.getRequestParamString("detail_url");
        Integer status = requestBean.getRequestParamInteger("status");
        String remark = requestBean.getRequestParamString("remark");
        Map<String,Object> yyDetailUrlMap =new HashMap<>(3);
        yyDetailUrlMap.put("detail_url",detailUrl);
        yyDetailUrlMap.put("status",status);
        yyDetailUrlMap.put("remark",remark);
        int num = yyDetailUrlDao.addYyDetailUrl(yyDetailUrlMap);
        responseBean.setResult(ResultConstant.SUCCESS);
        return responseBean;
    }

    /**
     * 修改广告推荐转入地址
     * @param requestBean
     * @return
     */
    public ResponseBean modYyDetailUrl(RequestBean requestBean){
        ResponseBean responseBean = requestBean.getResponseBean();
        Integer duId = requestBean.getRequestParamInteger("du_id");
        String detailUrl = requestBean.getRequestParamString("detail_url");
        Integer status = requestBean.getRequestParamInteger("status");
        String remark = requestBean.getRequestParamString("remark");
        Map<String,Object> yyDetailUrlMap = new HashMap<>(4);
        yyDetailUrlMap.put("du_id",duId);
        yyDetailUrlMap.put("detail_url",detailUrl);
        yyDetailUrlMap.put("status",status);
        yyDetailUrlMap.put("remark",remark);
        int num = yyDetailUrlDao.modYyDetailUrl(yyDetailUrlMap);
        responseBean.setResult(ResultConstant.SUCCESS);
        return responseBean;
    }
    /**
     * 删除广告推荐转入地址
     * @param requestBean
     * @return
     */
    public ResponseBean delYyDetailUrl(RequestBean requestBean) {
        ResponseBean responseBean = requestBean.getResponseBean();
        Integer duId = requestBean.getRequestParamInteger("du_id");
        int num = yyDetailUrlDao.delYyDetailUrl(duId);
        responseBean.setResult(ResultConstant.SUCCESS);
        return responseBean;
    }

    /**
     * 查询全部列表
     * @param requestBean
     * @return
     */
    public ResponseBean queryAllYyDetailUrl(RequestBean requestBean){
        ResponseBean responseBean = requestBean.getResponseBean();
        List<Map<String, Object>> yyDetailUrlList = yyDetailUrlDao.queryAllYyDetailUrl();
        responseBean.addResultItem("yyDetailUrlList", yyDetailUrlList);
        responseBean.setResult(ResultConstant.SUCCESS);
        return responseBean;
    }
}
